﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Models.SchemaModel>" MasterPageFile="~/Views/Shared/Content.Master"%>
<asp:Content runat="server" ContentPlaceHolderID="mainContent">
 <style>
                * {font-size:1em }
	            #toolbar {
		            padding: 10px 4px;
		            margin-bottom:8px;
	            }
	            #customToolbar {
		            padding: 10px 4px;
		            margin-bottom:8px;
	            }
	            
	            .ui-toolbar-dropdown
	            {
	                margin-left:5px;
	                margin-right:5px;
	            }
    </style>

    <div id="schemaFrame" class="content" style="height:100%">

        <script language="javascript">
            $(document).ready(function () {
                var buttons = new Array();
                buttons.push({ text: 'Create Master Page Template', hasText: false, id: 'addMasterPageTemplate', icon: '<%=Url.Content("~/Images/Icons/layout_add.png")%>' });
                buttons.push({ text: 'Create Page Template', hasText: false, id: 'addPageTemplate', icon: '<%=Url.Content("~/Images/Icons/page_add.png")%>' });
                MethodWorx.CMS.Toolbar.setButtons(buttons, "#toolbar");


                $("#createRootPage").click(function () {
                    createRootPageTemplate();
                });
                $("#createMasterPageTemplate").click(function () {
                    createMasterPageTemplate();
                });

                $("#addMasterPageTemplate").click(function () {
                    createMasterPageTemplate();
                });

                $("#addMasterPageTemplate").click(function () {
                    window.parent.openDialog("<%=Url.Content("~/AbstractPageTemplate/CreateFromTemplate")%>", "Create Master Page");
                });

                initializeCustomToolbar();
            });


            function initializeCustomToolbar() {
                $.ajax({ url: "<%=Url.Content("~/Schema/GetToolbarIdeExtensions")%>", dataType: "json", success: function (data) {
                    MethodWorx.CMS.Toolbar.setButtons(data);
                    for (var i = 0; i < data.length; i++) {
                        var action = data[i].action;
                        var text = data[i].text;
                        $("#" + data[i].id).click(function () {
                            window.parent.openDialog(action, text)
                        });
                    }
                }, cache: false
                });
        }


        function deleteContentTemplate(pageTemplateId, constraintId) {
            window.parent.openDialog("<%=Url.Content("~/Schema/DeleteContentTemplate")%>/" + pageTemplateId + "?constraintId=" + constraintId, "Delete Content Template");
        }

        function deletePageTemplate(pageTemplateId, constraintId) {
            window.parent.openDialog("<%=Url.Content("~/Schema/DeletePageTemplate")%>/" + pageTemplateId + "?constraintId=" + constraintId, "Delete Page Template");
        }


            function createPageTemplate(id) {
                var items = new Array();

                items.push({ name: 'Create/Add Page Template', src: '<%=Url.Content("~/PageTemplate/Create")%>/' + id });
                window.parent.setContextMenu(items);
            }


            function createMasterPageTemplate() {
                var items = new Array();

                items.push({ name: 'Create Master Page Template', src: '<%=Url.Content("~/AbstractPageTemplate/Create")%>' });
                items.push({ name: 'Properties', enabled: false });
                window.parent.setContextMenu(items);
            }

            function createContentTemplate(id) {
                var items = new Array();

                items.push({ name: 'Create/Add Content Template', src: '<%=Url.Content("~/ContentTemplate/Create")%>/' + id });
                window.parent.setContextMenu(items);
            }

            function createRootPageTemplate() {
                var items = new Array();
                items.push({ name: 'Root Page Template', src: '<%=Url.Content("~/PageTemplate/CreateRoot")%>' });
                window.parent.setContextMenu(items);
            }

            function configureContentTemplate(id) {
                var items = new Array();

                items.push({ name: 'Basic Details', src: '<%=Url.Content("~/ConfigureContentTemplate/BasicDetails")%>/' + id });
                items.push({ name: 'Properties', src: '<%=Url.Content("~/ConfigureContentTemplate/Properties")%>/' + id });
                window.parent.setContextMenu(items);
            }

            function configurePageTemplate(id) {
                var items = new Array();

                items.push({ name: 'Basic Details', src: '<%=Url.Content("~/ConfigurePageTemplate/BasicDetails")%>/' + id });
                items.push({ name: 'Properties', src: '<%=Url.Content("~/ConfigurePageTemplate/Properties")%>/' + id });
                items.push({ name: 'Template', src: '<%=Url.Content("~/ConfigurePageTemplate/EditTemplate")%>/' + id });

                //
                // here we need to get the extension points for the menu item
                $.getJSON("<%=Url.Content("~/ConfigurePageTemplate/GetIdeExtensions")%>/" + id, null, function (data) {
                    //
                    //  ok, here we go
                    for (var i = 0; i < data.length; i++) {
                        items.push({ name: data[i].Name, src: '<%=Url.Content("~/Plugin/PageTemplate")%>/' + data[i].Id + '/' + id });
                    }
                    window.parent.setContextMenu(items);
                });
            }
        </script>
                    <div
                        <h3>Master Page Templates</h3>
                        <%if(this.Model.AbstactPageTemplates.Any()) { %>
                        <div style="margin:2px;padding:2px">
                            <%foreach(var pt in this.Model.AbstactPageTemplates) { %>
                                <div style="padding:5px;margin:5px;border:1px solid silver; background-color:#DDDDDD;float:left;"><%=pt.Name %>
                                   <a href="javascript:configurePageTemplate('<%=pt.Id%>')">
                                    <img title="Configure Master Page Template" class="ui-icon ui-icon-gear"></img>
                                    </a>
                                    </div>
                            <%} %>
                            </div>
                            <div style="clear:both" />
                        <%} else { %>
                          <div style="text-align:center">
                            <p>No master page templates have been defined.</p>
                                <button type="button" id="createMasterPageTemplate">Create Master Page Template</button>
                            </div>
                            <%} %>
                    </div>
                    <div>
                        <h3>Website Schema</h3>
                    
                    <%if(this.Model.RootPageTemplate == null){ %>
                    <div style="text-align:center">
                        <p>No root page template has been defined.  This is usually your the home page for the website.</p>
                        <button type="button" id="createRootPage">Create Root Page Template</button>
                    </div>
                    <%} else {%>
                        <%Html.RenderPartial("PageTemplateView", this.ViewData.Model.RootPageTemplate); %>
                    <%} %>
                    </div>
    </div>
</asp:Content>